<?php

	// install the table
	add_action('activate_pluginurl','feed2blog_install');
	
	// function to install the table
	function feed2post_install () {
   		global $table_prefix, $wpdb;
				$table_name = $table_prefix . "feed2blog";

		// check if table exists
		if($wpdb->get_var("show tables like '$table_name'") != $table_name){
			
				$sql =	"CREATE TABLE" .  $tablename 
						. "(`id` INT( 10 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
						 `feed` VARCHAR( 80 ) NOT NULL ,
 						`update` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ,
 						`schedule` TIMESTAMP NOT NULL
						);";
				

				require_once(ABSPATH . 'wp-admin/upgrade-functions.php');
    			dbDelta($sql);

				// initialise the values
				$feedme = 'http://blog.adrianwong.org';
				$newdate = date('Y-m-d H:i:s', strtotime("+1 hour"));

				// prepare $sql query to create the table
				$insert = "INSERT INTO ".$table_name.
                			" (feed,update,schedule) ".
                			"VALUES ('"
                			.$feedme
                			."',"
                			."'"
                			."',"
                			."'"
                			.$newdate
                			."')";
    
    			// create the table            
				$results = $wpdb->query( $insert );
	
		}
	}

?>